package kit.docker.exception;

import com.docker.core.constant.ConfigConstant;
import kit.docker.web.APIResCode;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import org.apache.log4j.Logger;

public class BaseException extends RuntimeException {

    protected Integer status;

    protected String message;

    protected Object data;

    public BaseException() {
        super();
    }

    public BaseException(Integer status) {
        this.status = status;
    }

    public BaseException(String message) {
        Exception e = new Exception(message);
        Logger.getLogger(BaseException.class).error("Exception:" + message, e);
        if (PropKit.getBoolean(ConfigConstant.SYS_DEV_MODEL)) {
            e.printStackTrace();
        }
        this.message = message;
    }

    public BaseException(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    public BaseException(Object data, Integer status, String message) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public Integer getStatus() {
        return null == status ? APIResCode.FAIL : status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    public String getMessage() {
        return StrKit.isBlank(message) ? APIResCode.resCodeMap.get(getStatus()) : message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
